package org.spring.springboot.app.demo.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Delete;
import org.spring.springboot.app.base.ApiIndex;
import org.spring.springboot.app.base.R;
import org.spring.springboot.app.demo.domain.vo.DemoVO;
import org.spring.springboot.util.Uuid;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName DomeController
 * @Author HandsomeBugs
 * @Date 2019/3/20 17:04
 * @Version 1.0
 **/

@Api(description = "Demo相关接口", tags = ApiIndex.Demo)
@RequestMapping(value = "/api/demo")
@RestController
public class DemoController {

    @ApiOperation(value = "GET数据请求")
    @GetMapping(value = "")
    public R<List<DemoVO>> demoGet(
            @ApiParam(value = "需要得到数据数量", required = true) @RequestParam(defaultValue = "1") Integer num
    ) {
        List<DemoVO> list= new ArrayList<>();
        for (int i = 0; i < num; i++) {
            DemoVO demo=new DemoVO();
            demo.setId(Uuid.getUUID());
            demo.setName("随机名称"+Uuid.getUUID());
            list.add(demo);
        }
        return new R().setData(list);
    }


    @ApiOperation(value = "Post数据请求")
    @PostMapping(value = "")
    public R<DemoVO> demoPost(
            @ApiParam(value = "添加参数") @RequestBody DemoVO demoVO
    ) {
        return new R().setData(demoVO).setMessage("已经得到你请求添加的数据");
    }

    @ApiOperation(value = "Put数据请求")
    @PutMapping(value = "")
    public R<DemoVO> demoPut(
            @ApiParam(value = "修改参数")  @RequestBody DemoVO demoVO
    ) {
        return new R().setData(demoVO).setMessage("已经得到你请求修改的数据");
    }

    @ApiOperation(value = "Delete数据请求")
    @DeleteMapping(value = "")
    public R demoDelete(
            @ApiParam(value = "需要删除数据ID", required = true) @RequestParam(defaultValue = "") String id
    ) {
        return new R().setData("你需要删除数据ID:"+id);
    }

}
